<?php

declare(strict_types=1);

namespace App\Controller\Pda\v1;

use App\Controller\AbstractController;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\Di\Annotation\Inject;
use App\Middleware\PdaMiddleware;
use Hyperf\HttpServer\Annotation\Middleware;
use Service\StorageService\StorageBondedOrderService;
use Service\StorageService\StockService;
use Service\StorageService\StockSearchHistoryService;
use Service\StorageService\StockInService;
use Service\StorageService\InventoryService;

/**
 * 库存控制器
 * @Controller(prefix="/pda/v1/stock")
 * @Middleware(PdaMiddleware::class)
 */
class StockController extends AbstractController
{
    
    
    /**
     * 获取关务入库单
     * @RequestMapping(path="getstoragebondedorder", methods="post")
     */
    public function getStorageBondedOrder(RequestInterface $request ,StorageBondedOrderService $storagebondedorder)
    {
        return $storagebondedorder->getInfoBySn($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getParsedBody());
    }
    /**
     * 获取关务入库单明细
     * @RequestMapping(path="getstoragebondedorderdetail", methods="post")
     */
    public function getStorageBondedOrderDetail(RequestInterface $request ,StorageBondedOrderService $storagebondedorder)
    {
        return $storagebondedorder->getInfoBySn($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getParsedBody());
    }
    /**
     * 获取关务入库单商品搜素
     * @RequestMapping(path="getstoragebondedordergoods", methods="post")
     */
    public function getStorageBondedOrderGoods(RequestInterface $request ,StorageBondedOrderService $storagebondedorder)
    {
        return $storagebondedorder->getInfoBySn($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getParsedBody());
    }
    /**
     * 搜索库存
     * @RequestMapping(path="searchstock", methods="post")
     */
    public function searchStock(RequestInterface $request ,StockService $stockservice)
    {
        return $stockservice->getStockBySearch($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getAttribute('manager_id'),$request->getParsedBody());
    }
    
    /**
     * 获取库存搜索历史
     * @RequestMapping(path="searchhistory", methods="post")
     */
    public function searchHistory(RequestInterface $request ,StockSearchHistoryService $stockSearchHistoryservice)
    {
        return $stockSearchHistoryservice->getList($request->getAttribute('manager_id'));
    }
    /**
     * 删除库存搜索历史
     * @RequestMapping(path="delsearchhistory", methods="post")
     */
    public function delSearchHistory(RequestInterface $request ,StockSearchHistoryService $stockSearchHistoryservice)
    {
        return $stockSearchHistoryservice->delSearchHistory($request->getAttribute('manager_id'));
    }
    
    /**
     * 保税入库
     * @RequestMapping(path="bondedstockin", methods="post")
     */
    public function bondedStockIn(RequestInterface $request ,StockInService $stockInservice)
    {
        return $stockInservice->storageBondedOrderStockIn($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getAttribute('manager_id'),$request->getParsedBody());
    }
    
    /**
     * 盘点列表
     * @RequestMapping(path="inventory", methods="post")
     */
    public function Inventory(RequestInterface $request ,InventoryService $inventoryservice)
    {
        return $inventoryservice->getLists($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getParsedBody());
    }
    
    /**
     * 获取盘点商品
     * @RequestMapping(path="searchinventorygoods", methods="post")
     */
    public function searchInventoryGoods(RequestInterface $request ,InventoryService $inventoryservice)
    {
        return $inventoryservice->getSingleGoods($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getParsedBody());
    }
    
    /**
     * 保存盘点数据
     * @RequestMapping(path="saveinventorystock", methods="post")
     */
    public function saveInventoryStock(RequestInterface $request ,InventoryService $inventoryservice)
    {
        return $inventoryservice->saveStock($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getParsedBody());
    }
    
     /**
     * 生成盘点差异
     * @RequestMapping(path="addinventorydiff", methods="post")
     */
    public function addInventoryDiff(RequestInterface $request ,InventoryService $inventoryservice)
    {
        return $inventoryservice->adddiff($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getAttribute('manager_id'),$request->getParsedBody());
    }
    
     /**
     * 作废盘点差异
     * @RequestMapping(path="cancelinventorydiff", methods="post")
     */
    public function cancelInventoryDiff(RequestInterface $request ,InventoryService $inventoryservice)
    {
        return $inventoryservice->cancelDiff($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getAttribute('manager_id'),$request->getParsedBody());
    }
    
    /**
     * 获取盘点差异
     * @RequestMapping(path="getinventorydiff", methods="post")
     */
    public function getInventoryDiff(RequestInterface $request ,InventoryService $inventoryservice)
    {
        return $inventoryservice->getDiff($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getParsedBody());
    }
    
    /**
     * 执行调整
     * @RequestMapping(path="executeinventorydiff", methods="post")
     */
    public function executeInventoryDiff(RequestInterface $request ,InventoryService $inventoryservice)
    {
        $data=$request->getParsedBody();
        $inventory_id=$data['inventory_id'];
        return $inventoryservice->confirm($inventory_id,$request->getAttribute('manager_id'),0);
    }
    
    /**
     * 获取库位
     * @RequestMapping(path="getstockloc", methods="post")
     */
    public function getStockLoc(RequestInterface $request ,StockService $srockservice)
    {
        return $srockservice->getStockLoc($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getParsedBody());
    }
    
    /**
     * 删除盘点单
     * @RequestMapping(path="delinventory", methods="post")
     */
    public function delInventory(RequestInterface $request ,InventoryService $inventoryservice)
    {
        return $inventoryservice->delInventory($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getAttribute('manager_id'),$request->getParsedBody());
    }
}
